<?php
/**
 * ucenter common class.
*/
class  UserComm
{
    
    public static $_login_url = NULL;
    
    public static function init() 
	{
		if (! isset($_SESSION)) session_start();
    }
    
    public static function check() 
	{
		if ( ! isset($_SESSION['user_id']) || $_SESSION['user_id'] == ''
			|| ! isset($_SESSION['user_name']) || $_SESSION['user_name'] == ''
			|| ! isset($_SESSION['user_email'])  || $_SESSION['user_email'] == ''
			|| ! isset($_SESSION['user_agent']) || $_SESSION['user_agent'] == '' )
			return FALSE;
		return TRUE;
    }
    
    public static function register( $_user_id, $_user_name, $_user_email ) 
	{
		$_SESSION['user_id'] = $_user_id;
		$_SESSION['user_name'] = $_user_name;
		$_SESSION['user_email'] = $_user_email;
		$_SESSION['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
    }
    
    public static function logout () 
	{
		$_SESSION['user_id'] = '';
		$_SESSION['user_name'] = '';
		$_SESSION['user_email'] = '';
		$_SESSION['user_agent'] = '';
    }
    
    public static function getUserName() 
	{
		if (isset($_SESSION['user_name'])) {
			return $_SESSION['user_name'];
		}
		return FALSE;
    }
    
    public static function getUID() 
	{
		return $_SESSION['user_id'];
    }
}